#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+10;
int n,c,a[N],b[N],mx,len,ans=1e18,dp[N];
signed main(){
	freopen("minimize.in","r",stdin);
	freopen("minimize.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>n>>c;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		mx=max(mx,a[i]),b[i]=a[i];
	}
	b[n+1]=0;
	if(n<=1000||mx<=10000000){
		sort(b+1,b+n+2);
		len=unique(b+1,b+n+2)-b-1;
		for(int i=1;i<=n;i++){
			int now=lower_bound(b+1,b+len+1,a[i])-b;
			for(int j=now;j<=len;j++)
				dp[j]+=b[j]-a[i];
			for(int j=1;j<now;j++)
				dp[j]+=c;
			for(int j=len-1;j>=1;j--)
				dp[j]=min(dp[j],dp[j+1]);
		}
		cout<<dp[1];
	}else if(c==0) cout<<0;
	else{
		int sum=0;
		for(int i=1;i<=n;i++)
			sum+=a[i],ans=min(ans,a[i]*i-sum+(n-i)*c);
		cout<<ans;
	}
	return 0;
}